package com.test.stream;

import java.util.stream.Stream;

public class StreamParalleDemo {
    public static void main(String[] args) {
        //System.out.println(String.format("本计算机的核数：%d",Runtime.getRuntime().availableProcessors()));
        Stream.of(1,2,3,4,5,6,7,8,9)
                .reduce((a,b)->{
                    System.out.println(String.format("%s : %d + %d = %d",
                            Thread.currentThread().getName(),a,b,a+b));
                    return a+b;
                }).ifPresent(System.out::println);

        //stream并行流
        Stream.of(1,2,3,4,5,6,7,8,9)
                .parallel()
                .reduce((a,b)->{
                    System.out.println(String.format("%s : %d + %d = %d",
                            Thread.currentThread().getName(),a,b,a+b));
                    return a+b;
                }).ifPresent(System.out::println);
    }
}
